home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 769 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: sdrc.com!thor!scjones
  2. From: larry.jones@sdrc.com (Larry Jones)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Q: char **foo, char *foo[], and char foo[][] ?
  5. Date: 19 Apr 1996 20:20:46 GMT
  6. Organization: SDRC Engineering Services
  7. Distribution: world
  8. Message-ID: <4l8siu$6r3@info1.sdrc.com>
  9. References: <4l33ok$oo2@Sherlock.lectra.fr> <KANZE.96Apr18105949@gabi.gabi-soft.fr>
  10. NNTP-Posting-Host: thor.sdrc.com
  11. Originator: scjones@thor
  12.  
  13. In article <KANZE.96Apr18105949@gabi.gabi-soft.fr>, kanze@gabi-soft.fr (J. Kanze) writes:
  14. > In article <4l33ok$oo2@Sherlock.lectra.fr> phil@rd.lectra.fr (Philippe
  15. > Maurisset) writes:
  16. > |> myexample()
  17. > |> {
  18. > |>     char foo[MAX_X][MAX_Y];
  19. > |>     ...
  20. > |>     myfunc( (char **)foo );
  21. > |> }
  22. > |> void myfunc( char *foo[MAX_X] )
  23. >                 ^^^^^^^^^^^^^^^^
  24. > Because it appears as a function parameter, this is actually a
  25. > declaration of a char**, and not a char*[].
  26. > So in fact, you have no type incompatibility to deal with.
  27.  
  28. Yes, you do.  While the cast in the call to myfunc matches the
  29. prototype, the cast itself is erroneous.  The type of foo is actually
  30. char (*)[MAX_Y]: a pointer to an array of characters.  Converting a
  31. pointer to an array into a pointer to a pointer is essentially
  32. meaningless and will not generally work.  The corrected example is:
  33.  
  34.     myexample()
  35.     {
  36.         char foo[MAX_X][MAX_Y];
  37.         ...
  38.         myfunc( foo );
  39.     }
  40.     void myfunc( char (*foo)[MAX_X] )
  41.  
  42. Even K&R I discusses this in 5.7 Multi-Dimensional Arrays.
  43. ----
  44. Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
  45. larry.jones@sdrc.com
  46. In a minute, you and I are going to settle this out of doors. -- Calvin
  47.